****SUMMARY STATS*********************************


****GROUP 1, MAIN SPECIFICATIONS**************
eststo clear
use "$LocalData\BartikAnalyticData_2digit.dta", clear




*Generating year-industry-shares for computation for Bartik analytics and SEs
		keep if year>2002  //Restricts to period of analysis
		
		levelsof year, local(y) //Creates a macro list of all years
		
		foreach year in `y' {
			foreach ind_var of varlist c_i_share_2000* {
				qui gen t`year'_`ind_var' = `ind_var' * (year == `year')
				}
			}
	
		qui tab year, gen(year_) //Generates year dummies
		drop year_1
		qui tab geography, gen(geography_) //Generates year dummies
		drop geography_1


sort geography year
local years  (year>2002) & abs(gsmall_dep1)<5 & gSmallFirm1!=.
eststo: xtivreg2 gsmall_dep1 year_* (gSmallFirm1 = bartikGS1)  if `years', fe cluster(cluster3)
gen mainsample = e(sample)
local years  mainsample==1


replace annualchange= annualchange/100
* Define control variables
local controls dlngdp unem_change pop_growth annualchange 
local controls2 dlngdp, unem_change, pop_growth, annualchange, gSmallFirm1, bartikGS1
gen miss =  missing(`controls2')

by geography: egen singleton = sum(mainsample)
gen sumstatsample = 1 if singleton>1 & singleton!=. & mainsample==1
drop singleton mainsample
*keep if miss==0
* Summary Statistics

*********************************************************************
*********************************************************************
*Table 1 Summary Stats
	eststo: estpost summarize ///
     gSmallFirm1 bartikGS1 gLargeFirm1 bartikGL1 gsmall_dep1 ///
	if sumstatsample==1, detail listwise
	
	eststo: estpost summarize dlngdp unem_change pop_growth annualchange ///
	  ///
	if sumstatsample==1, detail listwise

			local years  (year>2002) & abs(gmed_dep1)<5  & !missing(bartikGS1) & !missing(gSmallFirm1) & !missing(gsmall_dep1) 
			local controls ln_pop_2000 unem_2000 urban_2000 lnincome2000 lnbr2000 small_dep_share2000 
				
			local years  (year>2002) & abs(gmed_dep1)<5  & !missing(bartikGS1) & !missing(gSmallFirm1) & !missing(gsmall_dep1) 
			eststo: xtivreg2 gmed_dep1 year_* (gSmallFirm1 = bartikGS1)  if `years', fe cluster(cluster3)
			gen mainsample = e(sample)
	
	eststo: estpost summarize gmed_dep1 ///
	if mainsample==1, detail 

	drop mainsample
				
			local years  (year>2002) & abs(gbig_dep1)<5  & !missing(bartikGS1) & !missing(gSmallFirm1) & !missing(gsmall_dep1) 
			eststo: xtivreg2 gbig_dep1 year_* (gSmallFirm1 = bartikGS1)  if `years', fe cluster(cluster3)
			gen mainsample = e(sample)
	
	eststo: estpost summarize gbig_dep1 ///
	if mainsample==1, detail 

	
	eststo: estpost summarize   ///
	cl_dep acqHQ acq_dep gSmallFirm1 ///
	if sumstatsample==1, detail listwise

	eststo: estpost summarize   ///
	fail_dep gSmallFirm1 ///
	if sumstatsample==1, detail listwise

	
**Bank Variables

******************************************************************************
use "$LocalData\BankLevelAnalysis.dta", clear

qui tab year, gen(year_)

gen temp = 1 if small==1 & year==2002
bysort cert: egen small2002 = max(temp)
drop temp

sort cert year
merge m:1 cert using "$LocalData\BankCluster3_2013.dta"
keep if _merge==3

local Filters year>2002 & abs(bank_busdep)<=5 


sort cert year
local filterbus abs(bank_busdep)<1  & abs(bank_hhdep)<1   & year>2013 &  asset<10000000 & bank_busdep!=0 & L.busdep!=.
local filterHH  abs(bank_hhdep)<1   & abs(bank_busdep)<1  & year>2013 &  asset<10000000 & bank_busdep!=0 & L.busdep!=.

	eststo: estpost summarize   ///
	bank_busdep bank_hhdep bank_gSmallFirm1 ///
	if `filterbus', detail listwise
	esttab using "$LocalData\Tables\SumStatsRFS.csv", append ///


	
use "$LocalData\BankLevelAnalysis.dta", clear
drop cluster3

qui tab year, gen(year_)

gen temp = 1 if small==1 & year==2002
bysort cert: egen small2002 = max(temp)
drop temp

sort cert year
merge m:1 cert using "$LocalData\BankCluster3_2002.dta"
keep if _merge==3
* Restrict to banks with deposit growth positive or negative 500% or less


local Filters year>2002 & abs(bank_lndep)<=5 & SBquant2002!=. & small2002==1 &  Lsmall==1 & merger==0
eststo: xtivreg2 bank_lndep (bank_gSmallFirm1 = bank_bartikGS1 )  year_* if abs(bank_lndep)<5 & year>2002 & Lsmall==1  & `Filters', fe cluster(cert)
gen mainsample = e(sample)
local Filters mainsample==1
bysort cert: egen singlecert = sum(mainsample)
local Filters mainsample==1 & singlecert>1 


	preserve
	replace sbl = sbl/100 
	eststo: estpost summarize   ///
	bank_lndep bank_gSmallFirm1 bank_gLargeFirm1  sbl ///
	if `Filters', detail 
	restore

	
	
bysort year: egen bank_prov99 = pctile(bank_prov), p(99)
bysort year: egen bank_prov01 = pctile(bank_prov), p(1)

bysort year: egen roa99 = pctile(roa), p(99)
bysort year: egen roa01 = pctile(roa), p(1)

bysort year: egen bank_lnci99 = pctile(bank_lnci), p(99)
bysort year: egen bank_lnci01 = pctile(bank_lnci), p(1)

bysort year: egen bank_lnre99 = pctile(bank_lnre), p(99)
bysort year: egen bank_lnre01 = pctile(bank_lnre), p(1)

local Filters year>2002 & abs(bank_lndep)<=5 & small2002==1 &  Lsmall==1 & merger==0
xtivreg2 roa (bank_gSmallFirm1 = bank_bartikGS1 )  year_* if roa<roa99 & roa>roa01  & year>2002 & Lsmall==1  & `Filters' , fe cluster(cluster3)
gen roasample = e(sample)
local Filters roasample==1
bysort cert: egen roa_single = sum(roasample)
local Filters roasample==1 & roa_single>1

	
	eststo: estpost summarize   ///
	roa  ///
	if `Filters', detail 

local Filters year>2002 & abs(bank_lndep)<=5 & small2002==1 &  Lsmall==1 & merger==0
xtivreg2 bank_prov (bank_gSmallFirm1 = bank_bartikGS1 )  year_* if bank_prov<bank_prov99 & bank_prov>bank_prov01  & year>2002 & Lsmall==1  & `Filters' , fe cluster(cluster3)
gen provsample = e(sample)
local Filters provsample==1
bysort cert: egen prov_single = sum(provsample)
local Filters provsample==1 & prov_single>1

	eststo: estpost summarize   ///
	bank_prov  ///
	if `Filters', detail 

local Filters year>2002 & abs(bank_lndep)<=5 & small2002==1 &  Lsmall==1 & merger==0
xtivreg2 bank_lnci (bank_gSmallFirm1 = bank_bartikGS1 )  year_* if bank_lnci<bank_lnci99 & bank_lnci>bank_lnci01  & year>2002 & Lsmall==1  & `Filters' , fe cluster(cluster3)
gen cisample = e(sample)
local Filters cisample==1
bysort cert: egen ci_single = sum(cisample)
local Filters cisample==1 & ci_single>1

	eststo: estpost summarize   ///
	bank_lnci  ///
	if `Filters', detail 


local Filters year>2002 & abs(bank_lndep)<=5 & small2002==1 &  Lsmall==1 & merger==0	
xtivreg2 bank_lnre (bank_gSmallFirm1 = bank_bartikGS1 )  year_* if bank_lnre<bank_lnre99 & bank_lnre>bank_lnre01  & year>2002 & Lsmall==1  & `Filters' , fe cluster(cluster3)
gen resample = e(sample)
local Filters resample==1
bysort cert: egen re_single = sum(resample)
local Filters resample==1 & re_single>1

	eststo: estpost summarize   ///
	bank_lnre  ///
	if `Filters', detail 
	esttab using "$LocalData\Tables\SumStatsRFS.csv", replace ///
	collabels(\multicolumn{1}{c}{{Mean}} \multicolumn{1}{c}{{Median}} \multicolumn{1}{c}{{Std.Dev.}} \multicolumn{1}{l}{{Obs}}) ///
	cells("mean(fmt(%12.4f)) p50(fmt(%12.4f)) sd(fmt(%12.4f)) count(fmt(0))") label nonumber f noobs 
	
	  		
		
		
